<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Contact extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model(array('contact_model', 'user_profiles_model', 'classes_model'));
        $this->load->helper(array('form'));
    }

    function index() {
            $data['show_captcha'] = FALSE;
            $this->ingesup->render('contact/index', $data);
    }

    function send(){
        if (isset($_POST['from']) && isset($_POST['message'])){
            $this->load->helper(array('email'));
            if (valid_email($_POST['from'])){
                $options = $_POST;
                $options['to'] = 1;
                if ($this->contact_model->sendMessage($options)){
                    $this->ingesup->render('contact/messageSuccess');
                } else {
                    $data['show_captcha'] = FALSE;
                    $this->ingesup->render('contact/index', $data);
                }
            } else {
                redirect('/contact/');
            }
        } else {
            redirect('/contact/');
        }
    }
}